package cn.com.io.day20151214.control;

import cn.com.io.day20151214.pojo.Water;

import java.io.*;

/**
 * 自定义序列化(二)
 */
public class WaterTest {
    public static void main(String[] args) throws IOException {
        ObjectOutputStream oos = null;
        ObjectInputStream ois = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("water.txt"));
            Water water = new Water("YIBAO","怡宝",10,"2L");
            oos.writeObject(water);

            ois = new ObjectInputStream(new FileInputStream("water.txt"));
            Water waterGet = (Water)ois.readObject();
            System.out.println(waterGet.toString());
//            System.out.println(waterGet.getParentName());
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(oos !=null){
                oos.close();
            }
            if(ois !=null){
                ois.close();
            }
        }
    }
}
